<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改车辆车款')" />
    <th:block th:include="include :: summernote-css" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-car-edit" th:object="${car}">
            <input name="carId" th:field="*{carId}" type="hidden">
            <div class="form-group">
                <label class="col-sm-2 control-label">图片：</label>
                <div class="col-sm-8" th:include="system/common/file_upload :: multiple_img(_file_id='multipleFile',_file_type='img',_file_list=${@file.getFiles(carId,'car_info')})"/>
            </div>
            <div class="form-group">    
                <label class="col-sm-2 control-label">车款名称：</label>
                <div class="col-sm-8">
                    <input name="carName" th:field="*{carName}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-2 control-label">介绍：</label>
                <div class="col-sm-8">
                    <input type="hidden" class="form-control" th:field="*{content}">
                    <div class="summernote" id="content"></div>
                </div>
            </div>
<!--            <div class="form-group">    -->
<!--                <label class="col-sm-2 control-label">状态：</label>-->
<!--                <div class="col-sm-8">-->
<!--                    <div class="radio-box" th:each="dict : ${@dict.getType('sys_normal_disable')}">-->
<!--                        <input type="radio" th:id="${'status_' + dict.dictCode}" name="status" th:value="${dict.dictValue}" th:field="*{status}">-->
<!--                        <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>-->
<!--                    </div>-->
<!--                </div>-->
<!--            </div>-->
            <div class="form-group">
                <label class="col-sm-2 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control">[[*{remark}]]</textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">附件：</label>
                <div class="col-sm-8" th:include="system/common/file_upload :: multiple_img(_file_id='multipleCarFile',_file_type='file',_file_list=${@file.getFiles(carId,'car_info','file')})"/>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label"></label>
                <div class="col-sm-3"><button type="button" class="btn btn-success" onclick="submitHandler()">上传</button></div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: summernote-js" />
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <script th:inline="javascript">
        var prefix = ctx + "system/car";
        $("#form-car-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-car-edit').serialize());
            }
        }

        $(function() {
            // FileMultipleImg.init({busId: [[${car.carId}]], busType: 'car_info', fileType: 'img'});
            multipleFile_manager.init({busId: [[${car.carId}]], busType: 'car_info', fileType: 'img'});
            multipleCarFile_manager.init({busId: [[${car.carId}]], busType: 'car_info', fileType: 'file',groupType:'file'});
            $('.summernote').each(function(i) {
                $('#' + this.id).summernote({
                    lang: 'zh-CN',
                    dialogsInBody: true,
                    callbacks: {
                        onChange: function(contents, $edittable) {
                            $("input[name='" + this.id + "']").val(contents);
                        },
                        onImageUpload: function(files) {
                            var obj = this;
                            var data = new FormData();
                            data.append("file", files[0]);
                            $.ajax({
                                type: "post",
                                url: ctx + "common/upload",
                                data: data,
                                cache: false,
                                contentType: false,
                                processData: false,
                                dataType: 'json',
                                success: function(result) {
                                    if (result.code == web_status.SUCCESS) {
                                        $('#' + obj.id).summernote('insertImage', result.url);
                                    } else {
                                        $.modal.alertError(result.msg);
                                    }
                                },
                                error: function(error) {
                                    $.modal.alertWarning("图片上传失败。");
                                }
                            });
                        }
                    }
                });
                var content = $("input[name='" + this.id + "']").val();
                $('#' + this.id).summernote('code', content);
            });
        });
    </script>
</body>
</html>